| Conditions | 1 |
| Paths | 1 |
| Total Lines | 84 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 17 | describe('Test database', function () { |
||
| 18 | before(function () { |
||
| 19 | db.add('subtitle', 'pob').store() |
||
| 20 | db.addEnv({'MOOV_SEARCH': 'dope'}) |
||
| 21 | }); |
||
| 22 | |||
| 23 | it ('expect to return an error if file is not a json', function () { |
||
| 24 | expect(() => { database.setFile('../db.txt') }).to.throw('The database file must be a json file') |
||
| 25 | }) |
||
| 26 | |||
| 27 | it ('expect database to be a string and equal parameter', function () { |
||
| 28 | expect(db.database) |
||
| 29 | .to.be.a('string') |
||
| 30 | .to.be.equal(file) |
||
| 31 | }) |
||
| 32 | |||
| 33 | it ('expect to be an object and contains subtitle property', function () { |
||
| 34 | expect(db.add('subtitle', 'pob').data) |
||
| 35 | .to.be.an('object') |
||
| 36 | .to.have.property('subtitle', 'pob') |
||
| 37 | }) |
||
| 38 | |||
| 39 | it ('expect file to exists and is a json', function () { |
||
| 40 | expect(file) |
||
|
|
|||
| 41 | .to.be.a.file() |
||
| 42 | .with.json |
||
| 43 | }) |
||
| 44 | |||
| 45 | it ('expect an error if file can\'t be created', function () { |
||
| 46 | expect(database.setFile('/home/db.json').add('key', 'value').store()) |
||
| 47 | .to.be.an.error |
||
| 48 | }) |
||
| 49 | |||
| 50 | it ('expect to be an empty object', function () { |
||
| 51 | expect(database.setFile('/home/db.json').get()) |
||
| 52 | .to.be.an('object') |
||
| 53 | .to.be.empty |
||
| 54 | }) |
||
| 55 | |||
| 56 | it ('expect to be an not empty object', function () { |
||
| 57 | expect(database.setFile(file).get()) |
||
| 58 | .to.be.an('object') |
||
| 59 | .to.not.empty |
||
| 60 | }) |
||
| 61 | |||
| 62 | it ('expect to be an object and contains subtitle', function () { |
||
| 63 | expect(db.get()) |
||
| 64 | .to.be.an('object') |
||
| 65 | .to.have.property('subtitle', 'pob') |
||
| 66 | }) |
||
| 67 | |||
| 68 | it ('expect to be a string and is equal pob', function () { |
||
| 69 | expect(db.get('subtitle')) |
||
| 70 | .to.be.an('string') |
||
| 71 | .to.be.equal('pob') |
||
| 72 | }) |
||
| 73 | |||
| 74 | it ('expect an error if key don\'t exists in file', function () { |
||
| 75 | expect(() => { db.get('potatoes') }) |
||
| 76 | .to.throw('potatoes is undefined') |
||
| 77 | }) |
||
| 78 | |||
| 79 | it ('expect an error if typeof is not a object', function () { |
||
| 80 | expect(() => { db.massive('test') }) |
||
| 81 | .to.throw('data must be an object') |
||
| 82 | }) |
||
| 83 | |||
| 84 | it ('expect to be an object', function () { |
||
| 85 | expect(db.massive({'subtitle': 'pob', 'quality': '720p'}).data) |
||
| 86 | .to.be.an('object') |
||
| 87 | .to.have.property('subtitle') |
||
| 88 | }) |
||
| 89 | |||
| 90 | it ('expect an error if parameter is not a object', function () { |
||
| 91 | expect(() => { db.addEnv('test') }) |
||
| 92 | .to.throw('data must be an object') |
||
| 93 | }) |
||
| 94 | |||
| 95 | it ('expect to be an object and contains search', function () { |
||
| 96 | expect(process.env) |
||
| 97 | .to.be.an('object') |
||
| 98 | .to.have.property('MOOV_SEARCH') |
||
| 99 | }) |
||
| 100 | }) |
||
| 101 |